Using state machines and callbacks to model friction and limit stops

Modeling friction is always an annoying task, requiring extra characterization of your system and convincing modeling tools to operate through all the nonlinearities of the model.

Here we'll make a state machine to think about the different states of the model and then use the VectorContinuousCallback feature of the Julia DifferentialEquations.jl package.

Consider a sliding mass system in which an external force is applied to the mass and the mass is subject to static and kinetic friction, and bounded by limit stops which abruptly stop its motion.

136 μs
27.0 ms

We can identify five different states for the system:

  • LEFT_STOP: mass against left stop, motion resisted by static friction and stop

  • SLIDING_RIGHT: mass moving, being resisted by dynamic friction

  • STOPPED: mass not against either stop, motion resisted by static friction

  • SLIDING_LEFT: like SLIDING_RIGHT but in the other direction

  • RIGHT_STOP: like LEFT_STOP but at the other end.

14.5 μs
19.3 μs

There are ten transitions between states, organized in eight lines:

  • LEFT_STOP to SLIDING_RIGHT if force (on the mass) is greater than static friction

  • SLIDING_RIGHT to STOPPED if speed drops to zero

  • SLIDING_RIGHT to RIGHT_STOP or SLIDING_LEFT (depending on COR) if position reaches right stop

  • STOPPED to SLIDING_RIGHT if force is greater than static friction

  • STOPPED to SLIDING_LEFT if force is greater than static friction (but in the other direction)

  • SLIDING_LEFT to STOPPED if speed drops to zero

  • SLIDING_LEFT to LEFT_STOP or SLIDING_RIGHT if position reaches left stop

  • RIGHT_STOP to SLIDING_LEFT if force is greater than static friction (but to the left)

14.6 μs

Let's enumerate our states and make a default parameter object using some tools from Parameters.jl.

4.2 μs
7.1 ms
Params
4.2 ms

Let's write a state-aware differential equation, and write a separate function for calculating the net force which can be used by both the ODE and by the callbacks for interpolating to the state change points.

2.7 μs
sbode (generic function with 1 method)
38.5 μs

The tests we use to move from one state to the other are defined in FricSMCondx, while the corresponding actions are defined in FricSMaffect!.

12.8 μs
FricSMCondx (generic function with 1 method)
41.1 μs
FricSMaffect! (generic function with 1 method)
52.4 μs
18.8 ms

Create a forcing function.

4.7 μs
force_ext (generic function with 1 method)
22.1 μs

Set up a sim function which sets initial conditions, timespan, parameters, and simulation options. We set dtmax = 0.01 because without it the solver skips forward too quickly.

6.5 μs
sim (generic function with 1 method)
28.0 μs
63.4 ms

Plot the results! Here we can see the system being pushed back and forth by an amplitude-modulated sinusoidal force.

5.5 μs
364 ms
158 ms

This notebook prepared using the Pluto reactive notebook system.

David Klaffenbach, 2021-01-01

6.6 μs